package com.blb.community.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @Author 帅帅
 * @Date 2022/7/12 15:03
 * @PackageName:com.blb.community.config
 * @ClassName: SexConverter
 * @Description: EasyExcel男女处理
 * @Version 1.0
 */
public class BusinessTypeConverter implements Converter<Integer> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Converter.super.supportJavaTypeKey();
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return Converter.super.supportExcelTypeKey();
    }

    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        return Converter.super.convertToJavaData(context);
    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        return Converter.super.convertToExcelData(context);
    }

    //导入
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if ("新增".equals(cellData.getStringValue())) {
            return 1;
        }
        if ("修改".equals(cellData.getStringValue())) {
            return 2;
        }
        if ("删除".equals(cellData.getStringValue())) {
            return 3;
        }
        return 4;
    }

   //导出
    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {

        if (value.equals(1)) {
         return    new WriteCellData<>("新增");
        }
        if (value.equals(2)) {
         return    new WriteCellData<>("修改");
        }
        if (value.equals(3)) {
            return    new WriteCellData<>("删除");
        }
        return new WriteCellData<>("其它");
    }

}
